
'use strict';

angular.module('myApp.statement', [])

.controller('statementCtrl', ['$scope','$http', 

    function($scope,$http) {
	    $http.get('v1/statement').success(function(data){
	        $scope.statement = data.message;
	         console.log(  data.message);
	    });

	    $scope.year_search = function(){
	    	var a = $('.checkf').val();
	    	if(!isNum(a)){
	    		alert("请输入数字格式的年份");
	    		$('.checkf').val('');
	    	}
	    	else {
				var search = {
					'search_time' : $(".checkf").val(),
					'search_type' : 'year'
		 		};
		 		console.log(search);
			    $http.post('v1/statement',search).success(function(data){
		            if(!data.error ){
		  			console.log(data);
		 			$scope.statement = data.message;           	
		            }else{
		                alert(data.message);
	            }
			    });
	    	}
	    }
	    $scope.season_search = function(){
	    	var a = $('.checks').val();
	    	if(!isNum(a)){
	    		alert("请输入数字格式的年份");
	    		$('.checks').val('');
	    	}
	    	else {
	    		var year = $(".checks").val();
	    		var season = $("#search_select").val();
	    		var my_var = year+"-"+season;
	    		console.log(my_var);
				var search = {
					'search_time' : my_var,
					'search_type' : 'quarter'
		 		};
		 		console.log(search);
			    $http.post('v1/statement',search).success(function(data){
		            if(!data.error ){
		  			console.log(data);
		 			$scope.statement = data.message;           	
		            }else{
		                alert(data.message);
	            }
			    });
	    	}
	    }
	    $scope.month_search = function(){
				var search = {
					'search_time' : $("#month").val(),
					'search_type' : 'month'
		 		};
		 		console.log(search);
			    $http.post('v1/statement',search).success(function(data){
		            if(!data.error ){
		  			console.log(data);
		 			$scope.statement = data.message;

		            }else{
		                alert(data.message);
	            }
			    });
		}
	//验证
		function isNum(a)
		{
		    // var reg = new RegExp("^\d{4}$");
		    var reg=/^\d{4}$/;
		    return reg.test(a);
		}
	    $('.year').bootstrapMonthpicker();

}]);